package com.ftg.learn.assess.controller;

import com.ftg.learn.assess.dto.AddAdminPageQueryDto;
import com.ftg.learn.assess.dto.AdminUpdateAssessDto;
import com.ftg.learn.assess.dto.AdminPageQueryDto;
import com.ftg.learn.assess.entity.Additional;
import com.ftg.learn.assess.entity.Assess;
import com.ftg.learn.assess.entity.Media;
import com.ftg.learn.assess.result.PageResult;
import com.ftg.learn.assess.result.Result;
import com.ftg.learn.assess.service.AdditionalService;
import com.ftg.learn.assess.service.AssessService;
import com.ftg.learn.assess.service.MediaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.ognl.Evaluation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/assess/admin")
@Tag(name = "管理端评价模块")
@AllArgsConstructor
public class AdminAssessController {
    @Autowired
    private final AssessService assessService;
    @Autowired
    private final AdditionalService additionalService;
    @Autowired
    private final MediaService mediaService;

    @PostMapping
    @Operation(summary = "管理员查看某个商品的评价(条件查询)")
    /**
     * 管理员查看某个商品的评价(条件查询)
     * @param queryDto
     * @return
     */
    public Result<PageResult> getProductAssess(@RequestBody AdminPageQueryDto queryDto) {
        return assessService.pageQuery(queryDto);
    }

    @GetMapping("/getAddition")
    @Operation(summary = "管理员查看某个商品的附加评价(条件查询)")
    public Result<List<Additional>> getAddition(@RequestParam("evaluationId") Long evaluationId) {
        return additionalService.MyPageageQuery(evaluationId);
    }

    /**
     * 管理员隐藏某个商品的评价
     * @param updateAssessDto
     * @return
     */
    @PutMapping
    @Operation(summary = "管理员隐藏某个商品的评价")
    public Result<String> updateProductAssess(@RequestBody AdminUpdateAssessDto updateAssessDto) {
        return assessService.updateProductAssess(updateAssessDto);
    }

    /**
     * 管理员删除某个商品的评价
     * @param evaluationId
     * @return
     */
    @DeleteMapping
    @Operation(summary = "管理员删除某个商品的评价")
    public Result<String> deleteProductAssess(@RequestParam("evaluationId") Long evaluationId) {
        return assessService.removeProductAssess(evaluationId);
    }

    @GetMapping("/additional")
    @Operation(summary = "根据评价id获取所有追评信息（管理端）")
    public Result<List<com.ftg.learn.assess.entity.Additional>> getAdditionalsByEvaluationId(@RequestParam("evaluationId") Long evaluationId) {
        return additionalService.getAdditionalsByEvaluationId(evaluationId);
    }
    //获取评价详情
    @GetMapping("/assessDetail")
    @Operation(summary = "获取评价的材料")
    public Result<List<Media>> getAssessDetail(@RequestParam("evaluationId") Long evaluationId){
        return mediaService.getAssessDetail(evaluationId);
    }
}
